package com.cisystem.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cisystem.common.annotation.Log;
import com.cisystem.common.core.controller.BaseController;
import com.cisystem.common.core.domain.AjaxResult;
import com.cisystem.common.enums.BusinessType;
import com.cisystem.system.domain.SysMailTemplate;
import com.cisystem.system.service.ISysMailTemplateService;
import com.cisystem.common.utils.poi.ExcelUtil;
import com.cisystem.common.core.page.TableDataInfo;

/**
 * 邮件模版Controller
 *
 * @author ruoyi
 * @date 2023-10-24
 */
@RestController
@RequestMapping("/system/template")
public class SysMailTemplateController extends BaseController
{
    @Autowired
    private ISysMailTemplateService sysMailTemplateService;

    /**
     * 查询邮件模版列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMailTemplate sysMailTemplate)
    {
        startPage();
        List<SysMailTemplate> list = sysMailTemplateService.selectSysMailTemplateList(sysMailTemplate);
        return getDataTable(list);
    }

    /**
     * 导出邮件模版列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:export')")
    @Log(title = "邮件模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMailTemplate sysMailTemplate)
    {
        List<SysMailTemplate> list = sysMailTemplateService.selectSysMailTemplateList(sysMailTemplate);
        ExcelUtil<SysMailTemplate> util = new ExcelUtil<SysMailTemplate>(SysMailTemplate.class);
        util.exportExcel(response, list, "邮件模版数据");
    }

    /**
     * 获取邮件模版详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysMailTemplateService.selectSysMailTemplateById(id));
    }

    /**
     * 新增邮件模版
     */
    @PreAuthorize("@ss.hasPermi('system:template:add')")
    @Log(title = "邮件模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMailTemplate sysMailTemplate)
    {
        return toAjax(sysMailTemplateService.insertSysMailTemplate(sysMailTemplate));
    }

    /**
     * 修改邮件模版
     */
    @PreAuthorize("@ss.hasPermi('system:template:edit')")
    @Log(title = "邮件模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMailTemplate sysMailTemplate)
    {
        return toAjax(sysMailTemplateService.updateSysMailTemplate(sysMailTemplate));
    }

    /**
     * 删除邮件模版
     */
    @PreAuthorize("@ss.hasPermi('system:template:remove')")
    @Log(title = "邮件模版", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysMailTemplateService.deleteSysMailTemplateByIds(ids));
    }
}